package tests.stepDefs;


import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import io.restassured.response.Response;
import org.junit.Assert;
import ru.weather.common.Steps;

/**
 * Определение шагов
 */
public class StepDefinitions extends Steps {

    private Response response;
    private String city;


    @Given("send request for weather in {string}")
    public void sendRequestForWeatherInCity(String name) {
        response = sendRequestForWeatherInCityStep(name);
        city = name;
    }

    @When("get correct answer")
    public void getCorrectAnswer() {
        int responseCode = response.then().log().all().extract().statusCode();
        Assert.assertEquals(200, responseCode);
    }

    @Then("check answer")
    public void checkAnswer() {
        checkAnswerStep(response, city);
        response=null;
    }

    @Given("send request with no API key")
    public void sendRequestWithNoAPIKey() {
        response = sendRequestWithNoAPIKeyStep();
    }

    @Given("send request with no q parameter")
    public void sendRequestWithNoQParameter() {
        response = sendRequestWithNoQParameterStep();
    }

    @Given("send request with wrong q parameter")
    public void sendRequestWithWrongQParameter() {
        response = sendRequestWithWrongQParameterStep();
    }

    @Given("send request with API key has been disabled.")
    public void sendRequestWithAPIKeyHasBeenDisabled() {
        response = sendRequestWithAPIKeyHasBeenDisabledStep();
    }

    @Then("answer {int}, {int}")
    public void answer(int status, int code) {
        answerStep(status, response, code);
        response=null;
    }
}
